package com.flag.liutao.common.config;

import com.flag.liutao.common.annotation.UnableSwagger;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import static com.google.common.base.Predicates.not;

@Configuration
public class SwaggerConfig {

    /**
     * 这是一个swagger的全局配置对象
     * @return
     */
    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        ApiInfo apiInfo = new ApiInfoBuilder()
                //配置swagger 配置文档的主题内容，name:文档发布者的名称，url,文档发布者的网站地址，email,给文档发布者发电子邮件的邮箱地址
                .contact(new Contact("godM","http://www.flag.com","2682512522@qq.com"))
                .title("国旗护卫队管理系统")//文档标题
                .description("刘滔出品，必属精品")//文档描述
                .version("1.0")
                .build();
        //配置API帮助文档的主体信息
        docket.apiInfo(apiInfo);
        docket = docket.select()
                //Predicates 是一个 多规则匹配工具
                .apis(Predicates.not(RequestHandlerSelectors.withMethodAnnotation(UnableSwagger.class)))//配置UnableSwagger注解添加后不生成配置文档
                .apis(RequestHandlerSelectors.basePackage("com.flag.liutao.modules"))//配置包扫描
                .paths(Predicates.or(PathSelectors.regex("/admin/.*"),PathSelectors.regex("/api/.*")))//使用正则表达式约束生成APi文档的约束
                .build();
        return docket;
    }
}
